package com.shuhua.taskServer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shuhua.pojo.entity.TeamMember;
import com.shuhua.pojo.vo.TeamMemberVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 班组成员Mapper接口
 */
@Mapper
public interface TeamMemberMapper extends BaseMapper<TeamMember> {
    
    /**
     * 查询班组成员详细信息
     * @param teamId 班组ID
     * @return 成员详细信息列表
     */
    @Select("SELECT tm.member_id, tm.craftsman_id, tm.join_time, " +
            "c.username, c.real_name, c.phone, c.avatar, " +
            "c.service_city, c.service_district, c.department, c.station, c.is_team_leader " +
            "FROM team_member tm " +
            "LEFT JOIN craftsman c ON tm.craftsman_id = c.id " +
            "WHERE tm.team_id = #{teamId}")
    List<TeamMemberVO> findMemberDetailsByTeamId(@Param("teamId") Long teamId);
    
    /**
     * 查询班组长详细信息
     * @param teamId 班组ID
     * @return 班组长详细信息
     */
    @Select("SELECT tm.member_id, tm.craftsman_id, tm.join_time, " +
            "c.username, c.real_name, c.phone, c.avatar, " +
            "c.service_city, c.service_district, c.department, c.station, c.is_team_leader " +
            "FROM team_member tm " +
            "LEFT JOIN craftsman c ON tm.craftsman_id = c.id " +
            "LEFT JOIN team t ON t.id = tm.team_id " +
            "WHERE tm.team_id = #{teamId} AND tm.craftsman_id = t.team_leader_id")
    TeamMemberVO findTeamLeaderByTeamId(@Param("teamId") Long teamId);
} 